home *** CD-ROM | disk | FTP | other *** search
/ Computer Inter@ctive 17 / Computer Interactive cdrom 17 - gen 99.iso / ZDNETIT / CONTENT / WEBDATA.ZIP / webdata.cgi < prev    next >
Encoding:
Text File  |  1998-08-10  |  58.2 KB  |  2,072 lines

  1. #
  2. # version 2.27c
  3. open(STDERR,">&STDOUT");
  4. &readparse;
  5. print "Content-type: text/html\n\n";
  6. #
  7. #********* BEGIN BODY********************
  8. $homepage="http://localhost/";
  9. $password="password";
  10. $cgilocation="webdata.cgi";
  11. $logfile='C:\WebSite\htdocs\dbname_data.log';
  12. $fieldnames='C:\WebSite\htdocs\dbname_fields.log';
  13. $members='C:\WebSite\htdocs\dbname_members.log';
  14. $reportdata='C:\WebSite\htdocs\dbname_report.log';
  15. $code='0000';
  16. #CHANGE SEARCHPAGE TO CUSTOM URL TO CHANGE "search again" LINK.
  17. $searchpage="$cgilocation?cgifunction=user";
  18.  
  19.  
  20. &user if ($user_data{cgifunction} eq "user");
  21. &add if ($user_data{cgifunction} eq "Add");
  22. &adminsearch  if ($user_data{cgifunction} eq "Search/modify");
  23. &maintenance if ($user_data{cgifunction} eq "maintenance");
  24. &delete if $user_data{cgifunction} eq "delete";
  25. &modify if $user_data{cgifunction} eq "modify";
  26. &admin if $user_data{cgifunction} eq "admin";
  27. &usersearch if $user_data{cgifunction} eq "Search";
  28. &import if $user_data{cgifunction} eq "Import data";
  29. &import2 if $user_data{cgifunction} eq "import2";
  30. &export if $user_data{cgifunction} eq "Export data";
  31. &export2 if $user_data{cgifunction} eq "export2";
  32. &cache if $user_data{cgifunction} eq "cache";
  33. &fieldmod if $user_data{cgifunction} eq "Modify fields";
  34. &deleteField if $user_data{cgifunction} eq "deleteField";
  35. &insertField if $user_data{cgifunction} eq "insertField";
  36. &renameField if $user_data{cgifunction} eq "renameField";
  37. &nextprev if $user_data{cgifunction} eq "Next Page";
  38. &nextprev if $user_data{cgifunction} eq "Previous Page";
  39. &members if $user_data{cgifunction} eq "Members";
  40. &addmember if $user_data{cgifunction} eq "Add Member";
  41. &deletemember if $user_data{cgifunction} eq "Delete Member";
  42. &memberpage if $user_data{cgifunction} eq "memberpage";
  43. &memberadd if $user_data{cgifunction} eq "add";
  44. &reportpage if $user_data{cgifunction} eq "Customize Pages";
  45. &modifyreport if $user_data{cgifunction} eq "Modify Pages";
  46. &deleteset if $user_data{cgifunction} eq "deleteset";
  47. &form if ($user_data{cgifunction} eq "form");
  48.  
  49. #*******BEGIN FORM SUBROUTINE******
  50. sub form {
  51. pop(@value);
  52. $id=$user_data{id};
  53.  
  54. open(REPORT, "<$reportdata"); 
  55. @reportData=<REPORT>;
  56. close REPORT;
  57. $reportColor=$reportData[0];
  58. chop($reportColor);
  59. $reportHeader=$reportData[1];
  60. chop($reportHeader);
  61. $reportHeader=~s/\<\;/</g;
  62. $reportHeader=~s/::/\n/g;
  63. $reportSequence=$reportData[2];
  64. chop($reportSequence);
  65. @sequence=split(/:/,$reportSequence);
  66. $reportSort=$reportData[3];
  67. chop($reportSort);
  68. $reportOrder=$reportData[4];
  69. chop($reportOrder);
  70. $reportLines=$reportData[5];
  71. chop($reportLines);
  72. $reportForm=$reportData[6];
  73. chop($reportForm);
  74.  
  75. print "
  76. <HEAD><TITLE>FORM DATA</TITLE></HEAD>
  77. <BODY BGCOLOR=\"$reportColor\">
  78. $reportHeader
  79. <TABLE width=100% bgcolor=white border=1>
  80. <TH WIDTH=20%><TH>
  81. ";
  82. open(FIELDS,"<$fieldnames")||die "Could not open $fieldnames";
  83. @fieldsData=<FIELDS>;
  84. close FIELDS;
  85. foreach (@fieldsData) {
  86.     ($field,$type)=split(/::/);
  87.     push(@fields,"$field\n");
  88.     push(@types,"$type");
  89. };
  90. shift(@fields);
  91. open(READLOG,"<$logfile")||die "Could not open $logfile";
  92. @entrydata = <READLOG>;
  93. close READLOG;
  94. foreach $entry (@entrydata) {
  95.     @parsed = split(/::/,$entry);
  96.     if ($parsed[0] eq $id) {@data = @parsed};
  97. };
  98. $num = @fields;
  99. shift(@data);
  100. for ($i=0;$i<$num;$i++) {
  101. #    $data[$i]=~s/\"/'"'/ge;
  102.     $data[$i]=~s/^([0-9a-zA-Z_\-\.\~]+\@[0-9a-zA-Z_\-\.\~]+\.[0-9a-zA-Z_\-\.\~]+)/<A HREF=mailto:$1>$1<\/A>/;
  103.     if ($data[$i]=~/^([^ ]+\.(gif|jpg))$/) {
  104.         $data[$i]="<IMG SRC=$1>";
  105.     } else {
  106.         $data[$i]=~s/^(http[^ ]+)/<A HREF=$1>$1<\/A>/;
  107.     };
  108.     print "<TR><TD><B>$fields[$i]<TD>$data[$i]\n";
  109. };
  110. print "
  111. </TABLE>
  112. <A HREF=\"$cgilocation?$user_data{query}\"><B>Back to Search Results</B></A> 
  113. \ \;
  114. <A HREF=\"$searchpage\"><B>Search Again</B></A>
  115. \ \;
  116. <A HREF=\"$homepage\"><B>Return to Homepage</B></A>
  117. ";
  118. };
  119.  
  120. #*******END FORM SUBROUTINE******
  121.  
  122. #******BEGIN DELETE SET SUBROUTINE*******
  123. sub deleteset {
  124. &memberpass;
  125. open(READLOG,"<$logfile");
  126. @entries = <READLOG>;
  127. close READLOG;
  128. foreach $line (@entries) {
  129.         @fields=split(/::/,$line);
  130.       $len=@fields;
  131.       $owner=$fields[$len-1];
  132.       chop($owner);
  133.       $id=$_;
  134.       if ((!($user_data{foundset}=~$fields[0]))||(($userid ne "admin")&&($userid ne $owner))) {
  135.              push(@result,$line);
  136.          };
  137. };
  138.  
  139.  
  140. open(PUTLOG, ">$logfile") || die "Content-type: text/html\n\n
  141. <BODY BGCOLOR=WHITE><CENTER><H2>Could not open the file $logfile<P>
  142. If you have moved the file, you can correct this by changing lines 10 and 11
  143. of the webdata_[database name].cgi script to show the absolute path to the file.<P><P><P></h2>
  144. This cgi error was ";
  145. print PUTLOG (@result);
  146. close PUTLOG;
  147.  
  148. @value=();
  149. if ($userid eq "admin") {&admin} else {&memberpage};
  150. };
  151.  
  152. #******END DELETE SET SUBROUTINE*********
  153.  
  154. #******BEGIN MODIFY REPORT.LOG FILE*******
  155. sub modifyreport {
  156. open(FILE,">$reportdata")||die "Could not open $reportdata";
  157. $user_data{header}=~s/\r\n/::/g;
  158. $user_data{header}=~s/\<\;/</g;
  159. $user_data{searchHeader}=~s/\r\n/::/g;
  160. $user_data{searchHeader}=~s/\<\;/</g;
  161. if ($user_data{form} eq "on") {
  162.     $form=1;
  163. } else {
  164.     $form=0;
  165. };
  166. #chop($user_data{seqnums});
  167. print FILE ("$user_data{color}\n$user_data{header}\n$user_data{seqnums}\n$user_data{sort}\n");
  168. print FILE ("$user_data{order}\n$user_data{numrows}\n$form\n");
  169. print FILE ("$user_data{searchHeader}\n$user_data{searchInfo}\n");
  170. close FILE;
  171. &reportpage;
  172. };
  173. #******END MODIFY REPORT.LOG FILE*******
  174.  
  175. #*******BEGIN REPORT PAGE SUBROUTINE********
  176. sub reportpage {
  177. &checkpass;
  178. open(FILE,"<$reportdata")||die "Could not open $reportdata";
  179. @reportData=<FILE>;
  180. close FILE;
  181.  
  182. open(FIELDS,"<$fieldnames")||die "Could not open $fieldnames";
  183. @fieldsData=<FIELDS>;
  184. close FIELDS;
  185. foreach (@fieldsData) {
  186.     ($field,$type)=split(/::/);
  187.     push(@fields,"$field\n");
  188.     push(@types,"$type");
  189. };
  190. shift(@fields);
  191. $len=@fields;
  192. $reportColor=$reportData[0];
  193. chop($reportColor);
  194. $reportHeader=$reportData[1];
  195.   chop($reportHeader);
  196.   $reportHeader=~s/</\<\;/g;
  197.   $reportHeader=~s/::/\n/g;
  198. $reportSequence=$reportData[2];
  199. chop($reportSequence);
  200. $reportSort=$reportData[3];
  201. chop($reportSort);
  202. $reportOrder=$reportData[4];
  203. chop($reportOrder);
  204. $reportLines=$reportData[5];
  205. chop($reportLines);
  206. $reportForm=$reportData[6];
  207. chop($reportForm);
  208. $searchHeader=$reportData[7];
  209.   chop($searchHeader);
  210.   $searchHeader=~s/</\<\;/g;
  211.   $searchHeader=~s/::/\n/g;
  212. $searchInfo=$reportData[8];
  213. chop($searchText);
  214.  
  215. print "
  216. <SCRIPT>
  217. nav=navigator.userAgent\;
  218. if (nav.indexOf(\'MSIE 3\')>0) {IE3=true} else {IE3=false}\;
  219.  
  220. function clearSequence (s) {
  221.     if (IE3) {
  222.       alert(\"Sorry, MSIE 3 does not support dynamic lists. \\nYou must use MSIE 4+ or Netscape 3+ to use this function\")\;
  223.     } else {
  224.       s.options.length=0\;
  225.       document.form1.seqnums.value=\"\"\;
  226.     }\;
  227. }\;
  228.  
  229. function setseq(L,R) {
  230.     if (IE3) {
  231.       alert(\"Sorry, MSIE 3 does not support dynamic lists. \\nYou must use MSIE 4+ or Netscape 3+ to use this function\")\;
  232.     } else {
  233.     var len=R.options.length\;
  234.     R.options.length++\;
  235.     i=L.selectedIndex\;
  236.     R.options[len].text=L.options[i].text\;
  237.     R.options[len].value=i\;
  238.     setnums(R)\;
  239.     }
  240. }\;
  241.  
  242. function setnums(s) {
  243.     var len=s.options.length\;
  244.     result=\"\"\;
  245.     for (i=0;i<len;i++) {
  246.         result+=s.options[i].value+\":\"
  247.     }\;
  248.     document.form1.seqnums.value=result\;
  249. }\;
  250.  
  251. </SCRIPT>
  252.  
  253. <BODY BGCOLOR=\"BEIGE\" onLoad=\"setnums(document.form1.sequence)\">
  254. <h3 align=center>Customize the color, sequence, and sort order of user search results</h3>
  255. <FORM NAME=\"form1\" ACTION=\"$cgilocation\" METHOD=POST>
  256. <B>Background Color:</B><BR>
  257. Enter a standard color or hex triplet<BR>
  258. \<\;BODY BGCOLOR=\"
  259. <INPUT TYPE=TEXT NAME=\"color\" VALUE=\"$reportColor\">\"><P>
  260. <P>
  261. <B>Header for search page:</B><BR>
  262. <I>This will go at the top of the search input form that users come to first.</I><BR>
  263. Enter any header text and/or images using HTML code:<BR>
  264. <TEXTAREA NAME=\"searchHeader\" COLS=60 ROWS=8 WRAP=VIRTUAL>$searchHeader</TEXTAREA><P>
  265.  
  266. <B>Include default search instructions on Search Page?</B> 
  267. <INPUT TYPE=CHECKBOX NAME=searchInfo VALUE=1";
  268. if ($searchInfo==1) {print " CHECKED"};
  269. print ">
  270. <P>
  271. <B>Header for results page:</B><BR>
  272. <I>This will go at the top of the search results table.</I><BR>
  273. Enter any header text and/or images using HTML code:<BR>
  274. <TEXTAREA NAME=\"header\" COLS=60 ROWS=8 WRAP=VIRTUAL>$reportHeader</TEXTAREA><P>
  275.  
  276. <B>Sequence of Fields:</B><BR>
  277. Click the fields in the left box in the sequence you wish <BR>
  278. to display them in the user search results table.<BR>
  279. You may leave out fields which you wish to hide from users<BR>
  280. <table border=0 cellpadding=10><tr><th>Avaliable fields<th>Report Columns (left to right)<tr><td align=center>
  281. <SELECT NAME=\"fields\" size=$len width=200 onChange=\"setseq(this,form.sequence)\">";
  282. foreach (@fields) {print "<OPTION>$_\n";};
  283. print "
  284. </SELECT> <td align=center><SELECT NAME=\"sequence\" size=$len width=200>";
  285.  
  286. @seq=split(/:/,$reportSequence);
  287. foreach (@seq) {
  288.     print "<OPTION VALUE=\'$_\'>$fields[$_]\n";
  289. };
  290. print "
  291. </SELECT><tr><td><td align=center>
  292. <input type=button value=\"Clear Sequence\" 
  293. onClick=\"clearSequence(form.sequence)\"></table></table><P>
  294. <input type=hidden name=\"seqnums\" value=\"\">
  295. <B>Sort by:<br></b>Choose the field by which you wish to sort</B>
  296. <SELECT NAME=\"sort\" size=1>";
  297. $i=1;
  298. print "<OPTION VALUE=\"0\">-- not sorted --\n";
  299. foreach (@fields) {
  300.     print "<OPTION VALUE=\"$i\"";
  301.         if ($reportSort == $i) {print " SELECTED";};
  302.     print ">$_\n";
  303.     $i++;
  304. };
  305. print "</SELECT>";
  306. print "<B>Sort Sequence:</B><SELECT NAME=\"order\"><OPTION VALUE=0>Ascending";
  307. print "<OPTION VALUE=1 ";
  308. if ($reportOrder==1) {print "SELECTED"}
  309. print ">Descending</SELECT>";
  310.  
  311.  
  312. print "<B>Number of results per page</B>
  313. <INPUT TYPE=text NAME=\"numrows\" SIZE=3 VALUE=\"$reportLines\"><P>
  314. <B>Include \"view\" button?</B>
  315. <INPUT TYPE=checkbox NAME=\"form\"";
  316. if ($reportForm==1) {print " CHECKED"};
  317. print "><BR>
  318. The view button appears next to each record in the user search results.  It displays the current record in a columnar form.
  319.  
  320.  
  321. <P>
  322. <INPUT TYPE=SUBMIT NAME=\"cgifunction\" VALUE=\"Modify Pages\"><BR>
  323. <A HREF=\'$cgilocation?cgifunction=admin\'>Return to Administration Page</A>
  324. </FORM>";
  325.  
  326. print "
  327. <A HREF=\"$searchpage\">Test your modifications on the User Search Page</A>";
  328. };
  329.  
  330.         
  331. #*******END REPORT PAGE SUBROUTINE**********
  332.  
  333. #********BEGIN MEMBERADD SUBROUTINE**************
  334. sub memberadd {
  335. &memberpass;
  336. open(FIELDS,"<$fieldnames")||die "Could not open $fieldnames";
  337. @fieldsData=<FIELDS>;
  338. close FIELDS;
  339. foreach (@fieldsData) {
  340.     ($field,$type)=split(/::/);
  341.     push(@fields,"$field\n");
  342.     push(@types,"$type");
  343. };
  344. @value=();
  345. $fcount=1;
  346. shift(@fields);
  347. foreach (@fields) {
  348.     chop($_) if (/\n$/);
  349.     $value[$fcount]=$user_data{$_};
  350.     $fcount++;
  351. };
  352. $value[0]=time();
  353. #pop(@value);  #** Remove cgifunction from @value array **
  354. #if ($user_data{pagenum}>0) {pop(@value)}; #** remove pagenum from @value array
  355. foreach (@value) {
  356.     $_=~s/\r/\n/g;
  357.     $_=~s/\n\n/\n/g;
  358.     $_=~s/\n/<BR>/g;
  359. };
  360. print "
  361. <HEAD><TITLE>Webdata Entry Added</TITLE></HEAD>
  362. <BODY BGCOLOR=\"BEIGE\"><H1>";
  363.  
  364. #******* Remove delimeter characters and leading spaces*********
  365. foreach $item (@value) {
  366.     $item=~s/^( *)//ge;   # remove leading spaces from entries
  367.     $item=~s/::/'::'/ge;  # replace delimiting character from entries
  368. };
  369.  
  370. #****Check to see if entry is already used****
  371. open(READLOG,"<$logfile");
  372. @entries = <READLOG>;
  373. $unique="true";
  374. foreach $line (@entries) {
  375.         @fields = split(/::/,$line);
  376.         if ($fields[0] eq $value[0]) {
  377.                 $unique="false";
  378.         };
  379. };
  380. close READLOG;
  381.  
  382.  
  383. #********Add values to $logfile file*******************
  384. if($unique eq "true") {
  385.      push(@value,"$userid");
  386.         open(LOGFILE,">>$logfile");
  387.     $line=join("::",@value);
  388.         print LOGFILE ("$line\n");
  389.         close(LOGFILE);
  390.         print "Your entry has been added.</H1><P>";
  391. } else {
  392.         print "<font color=\"red\">";
  393.         print "That ID key has already been used.  Click 'Search' to find or
  394. change it. Do not use Reload and Repost-Data</h1></font>";
  395. };
  396.  
  397. #****RETURN TO MAINTENANCE SCREEN****
  398. print "<A HREF=\"javascript:history.go(-1)\">
  399. Return to previous page</h1>
  400. ";
  401. };
  402. #*********END MEMBER ADD SUBROUTINE********************
  403.  
  404. #****BEGIN MEMBER PAGE SUBROUTINE
  405. sub memberpage {
  406.     &memberpass;
  407.     print "<SCRIPT>document.cookie=\"$cookie\"</SCRIPT>";
  408.         print "
  409. <HEAD><TITLE>Members Admin Page</TITLE></HEAD>
  410. <BODY BGCOLOR=\"beige\" 
  411. <H1 align=center> Members Administration Page </H1>
  412. <form name=\"form1\" action=\"$cgilocation\" method=post>
  413. <input type=hidden name=\"ID\">
  414. <TABLE BORDER=0>
  415. ";
  416. @fields=();
  417. @types=();
  418. open(FIELDS,"<$fieldnames")||die "Could not open $fieldnames";
  419. @fieldsData=<FIELDS>;
  420. close FIELDS;
  421. foreach (@fieldsData) {
  422.     ($field,$type)=split(/::/);
  423.     push(@fields,"$field\n");
  424.     push(@types,"$type");
  425. };
  426. shift(@fields);
  427. shift(@types);
  428.  
  429. foreach $field (@fields) {
  430.       &gettype($types[$ftcount]);
  431.       chop($field);
  432.       if ($type eq "text") {
  433.             print "<TR><TD><B>$field<TD><input type=$type name=\"$field\" size=$typesize>\n";
  434.       };
  435.       if ($type eq "checkbox") {
  436.           print "<TR><TD><B>$field<TD><input type=checkbox name=\"$field\" value=\"yes\">\n";
  437.       };
  438.       if ($type eq "list") {
  439.             print "<TR><TD><B>$field<TD><SELECT NAME=\"$field\" SIZE=1>\n";
  440.           print "<OPTION VALUE=\"\">\n";
  441.           foreach (@typelistvals) {
  442.             print "<OPTION>$_\n";
  443.           };
  444.           print "</SELECT>\n";
  445.       };
  446.       if ($type eq "comment") {
  447.           print "<TR><TD><B>$field<TD><TEXTAREA NAME=\"$field\" COLS=60 ROWS=$typerows></TEXTAREA>\n";
  448.       };
  449.       $ftcount++;
  450. };
  451. print "
  452. <!-- Do not change the values of the submit buttons -->
  453. </TABLE>
  454. <INPUT TYPE=SUBMIT NAME=\"cgifunction\" VALUE=\"add\">
  455. <INPUT TYPE=SUBMIT NAME=\"cgifunction\" VALUE=\"Search/modify\">
  456. <INPUT TYPE=RESET VALUE=\"Clear Form\"><P>
  457. </FORM> 
  458.  
  459.  
  460. <h2>
  461. Click \'Add\' to add a record to the database.
  462.  
  463. <P>To modify or delete a record: Search for the record, then click on the record in the search results window.</h2>
  464.  
  465. <A HREF=\"$homepage\">
  466. Return to home page</A>
  467.  
  468. ";
  469.  
  470. };
  471. #****END MEMBER PAGE SUBROUTINE
  472.  
  473. #*****BEGIN ADD MEMBER SUBROUTINE
  474. sub addmember {
  475.     if ($value[0] eq "admin") {
  476.         print "<SCRIPT>alert(\'admin is a reserved name\')</SCRIPT>";
  477.         &members;
  478.         exit;
  479.     };
  480.     open(FILE,"<$members");
  481.     @members=<FILE>;
  482.     close FILE;
  483.     foreach (@members) {
  484.         ($user,$pass)=split(/::/);
  485.         if ($value[0] eq $user) {
  486.             print "<SCRIPT>\n";
  487.             print "alert(\'That name is already used. Please choose another\')\n";
  488.             print "</SCRIPT>";
  489.             &members;
  490.             exit;
  491.         };
  492.     };
  493.     $pass=crypt($value[1],7);
  494.     $line="$value[0]::$pass\n";
  495.     open(FILE,">>$members");
  496.         print FILE ("$line");
  497.     close FILE;
  498.     &members;
  499. };
  500. #****END ADD MEMBER SUBROUTINE
  501.  
  502. #*****BEGIN DELETE MEMBER SUBROUTINE
  503. sub deletemember {
  504.     open(FILE,"<$members")||die "Could not open $members";
  505.     @oldlist=<FILE>;
  506.     close FILE;
  507.     foreach (@oldlist) {
  508.         ($user,$pass)=split(/::/);
  509.         if ($user ne $user_data{member}) {push(@newlist,$_)};
  510.     };
  511.     open(FILE,">$members")||die "Could not open $members";
  512.     print FILE (@newlist);
  513.     close FILE;
  514.     &members;
  515. };
  516. #****END DELETE MEMBER SUBROUTINE
  517.  
  518.  
  519. #****BEGIN ADD/REMOVE MEMBERS SUBROUTINE
  520. sub members {
  521.     &checkpass;
  522.     print "<body bgcolor=beige>\n<h1 align=center>Members</h1>\n";
  523.     open(FILE,"<$members");
  524.     @members=<FILE>;
  525.     close FILE;
  526.     $len=@members;
  527.     if ($len==0) {
  528.         print "No members have been created yet\n";
  529.     } else {
  530.         print "<FORM ACTION=\"$cgilocation\" METHOD=POST>\n";
  531.         print "<SELECT NAME=\"member\" size=$len>\n";
  532.         foreach (@members) {
  533.             ($user,$pass)=split(/::/);
  534.             print "<OPTION>$user\n";
  535.         };
  536.         print "</SELECT><BR>";
  537.         print "<INPUT TYPE=SUBMIT NAME=\"cgifunction\" VALUE=\"Delete Member\">\n";
  538.         print "</FORM>";
  539.     };
  540.         print "
  541. <HR><CENTER><B>Add A Member</B></CENTER>
  542. <TABLE BORDER=0>
  543. <FORM ACTION=\"$cgilocation\" METHOD=POST>
  544. <TR><TD><B>User Name</B><TD><INPUT TYPE=TEXT NAME=\"username\" SIZE=20><BR>
  545. <TR><TD><B>Password</B><TD><INPUT TYPE=TEXT NAME=\"password\" SIZE=20><BR>
  546. </TABLE>
  547. <INPUT TYPE=SUBMIT NAME=\"cgifunction\" VALUE=\"Add Member\">
  548. </FORM><BR><A HREF=\"$cgilocation?cgifunction=admin\">Return to Administration Page</A>    
  549.         ";
  550.     
  551. };
  552. #****END ADD/REMOVE MEMBERS SUBROUTINE
  553.  
  554. #*******BEGIN NEXTPREV SUBROUTINE*****
  555. # THIS SUBROUTINE REPLACES THE PAGENUM CRITERIA, THEN
  556. # RUNS THE USERSEARCH ROUTINE
  557. sub nextprev {
  558.     if ($user_data{cgifunction} eq "Next Page") {$n=1} else {$n=-1};
  559.     $p=$user_data{pagenum}+$n;
  560.     $q=$user_data{query};
  561.     $replace="pagenum=$p";
  562.     $find="pagenum=$user_data{pagenum}";
  563.     $q=~s/$find/$replace/;
  564.  
  565.     #EMPTY VALUE AND USER_DATA ARRAYS BEFORE RUNNING READPARSE
  566.     @value=();
  567.     %user_data=();
  568.     &readparse($q);
  569.     &usersearch if ($user_data{cgifunction} eq "Search");
  570.     &adminsearch  if ($user_data{cgifunction} eq "Search/modify");
  571. };
  572. #*******END NEXTPREV SUBROUTINE*******
  573. #*******BEGIN RENAMEFIELD SUBROUTINE***
  574. sub renameField {
  575.     &checkpass;
  576.     $select = $value[0];
  577.     $select++;
  578.     open(FIELDS,"<$fieldnames");
  579.     @fields=<FIELDS>;
  580.     close FIELDS;
  581.  
  582.     $newfield="$value[1]\n";
  583.     $fields[$select]=$newfield;
  584.     open(RESULT,">$fieldnames");
  585.     print RESULT (@fields);
  586.     close RESULT;
  587.  
  588. #****RETURN TO FIELD MODIFY SCREEN****
  589.     @value=();
  590.     &fieldmod;
  591. };
  592. #*******END RENAME FIELD SUBROUTINE****
  593.  
  594. #*******BEGIN INSERTFIELD SUBROUTINE****
  595. sub insertField {
  596.     &checkpass;
  597.     $select = $value[0];
  598.     $select++;
  599.     open(FIELDS,"<$fieldnames");
  600.     @fields=<FIELDS>;
  601.     close FIELDS;
  602.     $numfields=@fields;
  603.     $newfield="$fields[$select]$value[1]\n";
  604.     $fields[$select]=$newfield;
  605.     open(RESULT,">$fieldnames");
  606.     print RESULT (@fields);
  607.     close RESULT;
  608.  
  609.     open(RECORDS,"<$logfile");
  610.     @records = <RECORDS>;
  611.     close RECORDS;
  612.     foreach (@records) {
  613.     chop($_);
  614.     @linedata=split(/::/,$_);
  615.     $newdata="$linedata[$select]::";
  616.     $linedata[$select]=$newdata;
  617.     $newline=join('::',@linedata);
  618.     $_="$newline\n";
  619.     };
  620.     open(RECORDS,">$logfile");
  621.     print RECORDS (@records);
  622.     close RECORDS;
  623. #****RETURN TO FIELD MODIFY SCREEN****
  624.     @value=();
  625.     &fieldmod;
  626. };
  627.  
  628. #*******END INSERTFIELD SUBROUTINE******
  629.  
  630. #*******BEGIN DELETEFIELD SUBROUTINE****
  631. sub deleteField {
  632.     &checkpass;
  633.     $select = $value[0];
  634.     $select++;
  635.     open(FIELDS,"<$fieldnames");
  636.     @fields=<FIELDS>;
  637.     close FIELDS;
  638.     foreach $field (@fields) {
  639.     if ($field ne $fields[$select]) {
  640.         push(@result,$field);
  641.     }
  642.     }
  643.     open(FIELDS,">$fieldnames");
  644.     print FIELDS (@result);
  645.     close FIELDS;
  646.     
  647.     open(RECORDS,"<$logfile");
  648.     @records=<RECORDS>;
  649.     close RECORDS;
  650.     foreach $record (@records) {
  651.     chop($record);
  652.     @linedata=split(/::/,$record);
  653.     @newline=("");
  654.     $count=0;
  655.     foreach $item (@linedata) {
  656.         if ($count != $select) {
  657.         push(@newline,$item);
  658.         };
  659.         $count++;
  660.     };        
  661.     shift(@newline);
  662.     $record = join('::',@newline)."\n";
  663.     };
  664.     open(RECORDS,">$logfile");
  665.     print RECORDS (@records);
  666.     close RECORDS;
  667.     
  668. #****RETURN TO FIELD MODIFY SCREEN****
  669.     @value=();
  670.     &fieldmod;
  671.     
  672.  
  673. };
  674.  
  675. #*******END DELETEFIELD SUBROUTINE******
  676.  
  677. #*******BEGIN FIELDMOD SUBROUTINE********
  678. sub fieldmod {
  679.     &checkpass;
  680.     open(FIELDS,"<$fieldnames");
  681.     @fields=<FIELDS>;
  682.     close FIELDS;
  683.     shift(@fields);
  684.     $num=@fields;
  685.     $num++;
  686.     print "
  687. <HEAD>
  688. <TITLE>Webdata Modify Fields</TITLE>
  689. <SCRIPT>
  690. function insert(s) {
  691.    newfield=prompt(\"New Field Name:\",\"\")\;
  692.    if (!newfield) {return}\;
  693.     newtype=\"\"\;
  694.     while ((newtype!=\"text\")&&(newtype!=\"checkbox\")&&(newtype!=\"list\")&&(newtype!=\"comment\")) {
  695.         newtype=prompt(\"Enter text, checkbox, comment, or list\")\;
  696.         if(!newtype) {return}\;
  697.     }\;
  698.     if (newtype==\"text\") {
  699.         newval=\":\"+prompt(\"Enter how many characters:\")
  700.         if (newval==\":null\") {return}\;
  701.     }\;
  702.     if (newtype==\"checkbox\") {newval=\"\"}\;
  703.     if (newtype==\"list\") {
  704.         newval=\":\"+prompt(\"Enter each value in list with a comma in between:\")
  705.         if(newval==\":null\") {return}\;
  706.     }\;
  707.     if (newtype==\"comment\") {
  708.         newval=\":\"+prompt(\"Enter how many rows high you would like the comment box:\")\;
  709.         if(newval==\":null\") {return}\;
  710.     }\;
  711.  
  712.    document.form2.newFieldName.value=newfield+\"::\"+newtype+newval\;
  713.    document.form2.selectedField.value=s.selectedIndex\;
  714.    document.form2.cgifunction.value=\"insertField\"\;
  715.    document.form2.submit()\;
  716. }
  717.  
  718. function del(s) {
  719.    if (s.selectedIndex<0) {return}
  720.    message=\"Are you sure you want to delete the selected field?\\n\"\;
  721.    message+=\" Any data contained in that field will be destroyed.\"\;
  722.    if(confirm(message)) {
  723.      document.form2.selectedField.value=s.selectedIndex\;
  724.      document.form2.cgifunction.value=\"deleteField\"\;
  725.      document.form2.submit()\;
  726.    }
  727. }
  728.  
  729. function rename(s) {
  730.     oldfield=s.options[s.selectedIndex].text\;
  731.     del1=oldfield.indexOf(\'::\')\;
  732.     oldname=oldfield.substring(0,del1)\;
  733.     oldfield=oldfield.substring(del1+2,9999)\;
  734.     del1=oldfield.indexOf(\':\')\;
  735.     if (del1==-1) {del1=9999}\;
  736.     oldtype=oldfield.substring(0,del1)\;
  737.     oldfield=oldfield.substring(del1+1,9999)\;
  738.     oldvalue=oldfield.substring(0,9999)\;
  739.  
  740.    newfield=prompt(\"New Field Name:\",oldname)\;
  741.    if (!newfield) {return}\;
  742.     newtype=\"\"\;
  743. while ((newtype!=\"text\")&&(newtype!=\"checkbox\")&&(newtype!=\"list\")&&(newtype!=\"comment\")) {
  744.         newtype=prompt(\"Enter text, checkbox, comment, or list\",oldtype)\;
  745.         if(!newtype) {return}\;
  746.     }\;
  747.     if (newtype!=oldtype) {oldvalue=\"\"}\;
  748.     if (newtype==\"text\") {
  749.         newval=\":\"+prompt(\"Enter how many characters:\",oldvalue)
  750.         if (newval==\":null\") {return}\;
  751.     }\;
  752.     if (newtype==\"checkbox\") {newval=\"\"}\;
  753.     if (newtype==\"list\") {
  754.         newval=\":\"+prompt(\"Enter each value in list with a comma in between:\",oldvalue)
  755.         if(newval==\":null\") {return}\;
  756.     }\;
  757.     if (newtype==\"comment\") {
  758.         newval=\":\"+prompt(\"Enter how many rows high you would like the comment box:\",oldvalue)\;
  759.         if(newval==\":null\") {return}\;
  760.     }\;
  761.  
  762.    document.form2.newFieldName.value=newfield+\"::\"+newtype+newval\;
  763.    document.form2.selectedField.value=s.selectedIndex\;
  764.    document.form2.cgifunction.value=\"renameField\"\;
  765.    document.form2.submit()\;
  766.  
  767. }
  768.  
  769. function admin() {
  770.    document.form2.cgifunction.value=\"admin\"\;
  771.    document.form2.submit()\;
  772. }
  773.  
  774. function clear() {
  775.    document.form1.list.selectedIndex=-1;
  776. }
  777.  
  778.  
  779.    
  780.  
  781.  
  782. </SCRIPT>
  783. </HEAD>
  784. <BODY BGCOLOR=\"beige\">
  785. <H1>Modify Field List</H1>
  786. <FORM NAME=\"form1\" ACTION=\"$cgilocation\" METHOD=POST>
  787. <TABLE BORDER=0><TR><TD>
  788. <SELECT NAME=\"list\" SIZE=$num>
  789. ";
  790.     foreach $field (@fields) {
  791.     chop($field);
  792.     print "<OPTION VALUE=\"$field\">$field\n";
  793.     };
  794.  
  795.     print "
  796. </SELECT>
  797. <TR><TD>
  798.  
  799. <P><INPUT TYPE=\"BUTTON\" VALUE=\"INSERT FIELD BELOW SELECTION\"
  800. onClick=\"insert(form.list)\"><BR>
  801. <INPUT TYPE=\"BUTTON\" VALUE=\"DELETE SELECTED FIELD\"
  802. onClick=\"del(form.list)\"><BR>
  803. <INPUT TYPE=\"BUTTON\" VALUE=\"REDEFINE SELECTED FIELD\"
  804. onClick=\"rename(form.list)\">
  805.  
  806.  
  807. </TABLE>
  808.  
  809. </FORM>
  810. To create a text box: Click Insert or Redefine field.  Enter the field\'s name in the first prompt box.  Enter the word \"text\" in the second prompt box.  Enter the SIZE in number of characters for the new text box.<P>
  811.  
  812. To create a checkbox: Click Insert or Redefine field.  Enter the field\'s name in the first prompt box.  Enter the word \"checkbox\" in the second prompt box.  That's it.<P>
  813.  
  814. To create a selection list: Click Insert or Redefine field. Enter the field\'s name in the first prompt box.  Enter the 
  815. word \"list\" in the second prompt box.  In the third prompt box, enter the list of values, seperated by a comma without spaces around the comma.  For example.<BR><B>Fire Engine Red,Lemon Yellow,Medium Blue,Salmon,Crimson,Ash White</B><P>
  816.  
  817. To create a textarea box for comments: Click Insert or Redefine field. Enter the field\'s name in the first
  818. prompt box.  Enter the word \"comment\" in the second prompt box.  In the third box, enter the number of rows high you wish
  819. to make your comment box. It will have a width of 60 characters.
  820. <P>
  821. <A HREF=\"javascript:admin()\">Return to Administration Page</A>
  822. <P>
  823. To insert a field at the <i>top</i> of the list, do not select anything.<BR>
  824. <A HREF=\"javascript:clear()\">
  825. Click here to clear the selection</A>
  826. <FORM NAME=\"form2\" ACTION=\"$cgilocation\" METHOD=POST>
  827. <INPUT TYPE=HIDDEN NAME=\"selectedField\">
  828. <INPUT TYPE=HIDDEN NAME=\"newFieldName\">
  829. <INPUT TYPE=HIDDEN NAME=\"cgifunction\">
  830. ";
  831.  
  832. };
  833.  
  834.  
  835. #*******END FIELDMOD SUBROUTINE**********
  836.  
  837. #*******BEGIN USER SUBROUTINE*************
  838. sub user {
  839. open(FIELDS,"<$fieldnames")||die "Could not open $fieldnames";
  840. @fieldsData=<FIELDS>;
  841. close FIELDS;
  842. foreach (@fieldsData) {
  843.     ($field,$type)=split(/::/);
  844.     push(@fields,"$field\n");
  845.     push(@types,"$type");
  846. };
  847. shift(@fields);
  848. shift(@types);
  849. open(REPORT, "<$reportdata"); 
  850. @reportData=<REPORT>;
  851. close REPORT;
  852. $reportColor=$reportData[0];
  853. chop($reportColor);
  854. $searchHeader=$reportData[7];
  855. chop($searchHeader);
  856. $searchHeader=~s/\<\;/</g; 
  857. $searchHeader=~s/::/\n/g; 
  858. $searchInfo=$reportData[8];
  859. chop($searchInfo);
  860. print "
  861. <HEAD><TITLE>Database Search</TITLE></HEAD>
  862. <BODY bgcolor=\"$reportColor\">
  863. $searchHeader
  864. ";
  865. if ($searchInfo==1) {
  866.      print " 
  867. <font size=3>
  868. Click \"Clear Form\" then \"Search\" to see all records.<BR>
  869. Enter text in any field to restrict the search to only those
  870. records which <I>CONTAIN</I> your text in that field.<P>
  871.  
  872. For numeric comparisons, begin with \>\;, \<\;,  \>\;=,  or \<\;=<BR>
  873. To find a range, type <TT><B>between</B> lowvalue <B>and</B>
  874. highvalue.</TT><BR>
  875. Do not use commas or dollar signs in numeric searches.<BR>
  876. Use \"and\" & \"or\" for complex searches.</font>
  877.      ";
  878. };
  879. print "<FORM NAME=\"form1\" ACTION=\"$cgilocation\" method=\"post\"> 
  880. <TABLE>
  881. ";
  882. $ftcount=0;
  883. foreach $field (@fields) {
  884.       &gettype($types[$ftcount]);
  885.       chop($field);
  886.       if ($type eq "text") {
  887.             print "<TR><TD><B>$field<TD><input type=$type name=\"$field\" size=$typesize>\n";
  888.       };
  889.       if ($type eq "checkbox") {
  890.           print "<TR><TD><B>$field<TD><input type=checkbox name=\"$field\" value=\"yes\">\n";
  891.       };
  892.       if ($type eq "list") {
  893.             print "<TR><TD><B>$field<TD><SELECT NAME=\"$field\" SIZE=1>\n";
  894.           print "<OPTION VALUE=\"\">\n";
  895.           foreach (@typelistvals) {
  896.             print "<OPTION>$_\n";
  897.           };
  898.           print "</SELECT>\n";
  899.       };
  900.       if ($type eq "comment") {
  901.           print "<TR><TD><B>$field<TD><TEXTAREA NAME=\"$field\" COLS=60 ROWS=$typerows></TEXTAREA>\n";
  902.       };
  903.       $ftcount++;
  904. };
  905. print "</TABLE>
  906. <BR>
  907. <input type=submit name=\"cgifunction\" value=\"Search\"> <!--FLAG3-->
  908. <input type=submit name=\"cgifunction\" value=\"Add\"> <!--FLAG1-->
  909. <input type=reset value=\"Clear Form\">
  910. </FORM>
  911. ";
  912.  
  913. };
  914.  
  915.  
  916. #*******END USER SUBROUTINE***************
  917.  
  918. #********BEGIN ADD SUBROUTINE**************
  919. sub add {
  920. &memberpass; #<!--FLAG2-->
  921. open(FIELDS,"<$fieldnames")||die "Could not open $fieldnames";
  922. @fieldsData=<FIELDS>;
  923. close FIELDS;
  924. foreach (@fieldsData) {
  925.     ($field,$type)=split(/::/);
  926.     push(@fields,"$field\n");
  927.     push(@types,"$type");
  928. };
  929. $fcount=1;
  930. shift(@fields);
  931. foreach (@fields) {
  932.     chop($_) if (/\n$/);
  933.     $value[$fcount]=$user_data{$_};
  934.     $fcount++;
  935. };
  936. $value[0]=time();
  937. #pop(@value);  #** Remove cgifunction from @value array **
  938. #if ($user_data{pagenum}>0) {pop(@value)}; #** remove pagenum from @value array
  939. foreach (@value) {
  940.     $_=~s/\r/\n/g;
  941.     $_=~s/\n\n/\n/g;
  942.     $_=~s/\n/<BR>/g;
  943. };
  944. print "
  945. <HEAD><TITLE>Webdata Entry Added</TITLE></HEAD>
  946. <BODY BGCOLOR=\"BEIGE\"><H1>";
  947.  
  948. #******* Remove delimeter characters and leading spaces*********
  949. foreach $item (@value) {
  950.     $item=~s/^( *)//ge;   # remove leading spaces from entries
  951.     $item=~s/::/'::'/ge;  # replace delimiting character from entries
  952. };
  953.  
  954. #****Check to see if entry is already used****
  955. open(READLOG,"<$logfile");
  956. @entries = <READLOG>;
  957. $unique="true";
  958. foreach $line (@entries) {
  959.         @fields = split(/::/,$line);
  960.         if ($fields[0] eq $value[0]) {
  961.                 $unique="false";
  962.         };
  963. };
  964. close READLOG;
  965.  
  966.  
  967. #********Add values to $logfile file*******************
  968. if($unique eq "true") {
  969.      push(@value,"admin");
  970.         open(LOGFILE,">>$logfile");
  971.     $line=join("::",@value);
  972.         print LOGFILE ("$line\n");
  973.         close(LOGFILE);
  974.         print "Your entry has been added.</H1><P>";
  975. } else {
  976.         print "<font color=\"red\">";
  977.         print "That ID key has already been used.  Click 'Search' to find or
  978. change it. Do not use Reload and Repost-Data</h1></font>";
  979. };
  980.  
  981. #****RETURN TO MAINTENANCE SCREEN****
  982. print "<A HREF=\"javascript:history.go(-1)\">
  983. Return to previous page</h1>
  984. ";
  985. };
  986. #*********END ADD SUBROUTINE********************
  987.  
  988.  
  989.  
  990. #**********BEGIN SEARCH SUBROUTINE******************
  991. sub adminsearch {
  992. &memberpass;
  993. pop(@value);   #** Remove cgifunction from @value array **
  994. #shift(@value); #** Remove hidden ID from top of @value array **
  995. if ($userid ne "admin") {push(@value,$userid)};
  996. print "
  997. <HEAD><TITLE>Webdata Admin Search</TITLE></HEAD>
  998. <SCRIPT>
  999.    function modify(sym) {
  1000.        document.form1.part.value=sym\;                
  1001.        document.form1.submit()\;
  1002.    }
  1003.  
  1004. function goadmin() {
  1005. document.form1.cgifunction.value=\"";
  1006. if ($userid eq "admin") {
  1007.     print "admin";
  1008. } else {
  1009.     print "memberpage"
  1010. };
  1011. print "\"\;
  1012. document.form1.submit()\;
  1013. }
  1014.  
  1015. function deleteset() {
  1016.     msg=\'This will permanently delete all of\\n\'+
  1017.     \'the records displayed on the screen.  Are you\\n\'+
  1018.     \'sure that you want to do this?\'\;
  1019.     if (confirm(msg)) {
  1020.         document.form1.cgifunction.value=\"deleteset\"\;
  1021.         document.form1.submit()\;
  1022.     }\;
  1023. }
  1024. </SCRIPT>\n
  1025.  
  1026. <H1 ALIGN=CENTER>Administration Search Page</H1>
  1027. ";
  1028.  
  1029. open(LOGFILE,"<$logfile");
  1030. @entries = <LOGFILE>;
  1031. close (LOGFILE);
  1032. print "<BODY BGCOLOR=\"BEIGE\">\n";
  1033. print "<TABLE BORDER=1 bgcolor=\"white\">\n";
  1034.  
  1035. open(FIELDS,"<$fieldnames")||die "Could not open $fieldnames";
  1036. @fieldsData=<FIELDS>;
  1037. close FIELDS;
  1038. foreach (@fieldsData) {
  1039.     ($field,$type)=split(/::/);
  1040.     push(@fields,"$field\n");
  1041.     push(@types,"$type");
  1042. };
  1043. $fcount=1;
  1044. @value=();
  1045. shift(@fields);
  1046. foreach (@fields) {
  1047.     chop($_) if (/\n$/);
  1048.     $value[$fcount]=$user_data{$_};
  1049.     $fcount++;
  1050. };
  1051. if ($userid ne "admin") {push(@value,$userid)};
  1052. shift(@value);
  1053. $header= "<TR>";
  1054. foreach $field (@fields) {
  1055.     $header .= "<TH>$field";
  1056. };
  1057. print  "$header\n";
  1058.  
  1059. #***** BEGIN STEPPING THROUGH ALL THE DATA LINES*****
  1060. #***** PARSE THE DATA *****************
  1061. foreach $line (@entries) {
  1062.     @fields = split(/::/,$line);
  1063.     $ID = shift(@fields);
  1064.  
  1065. # *** IF LINE MATCHES PATTERN ***********
  1066.     $display="true";
  1067.     $numPairs=@value;
  1068.     for ($i=0;$i<$numPairs;$i++) {
  1069.     if ($value[$i]=~/[0-9][0-9]?\/[0-9][0-9]?\/[0-9][0-9]+/) {
  1070.         $_=$value[$i];
  1071.         @temp=m/([0-9][0-9]?\/[0-9][0-9]?\/[0-9][0-9]+)/g;
  1072.         $temp[0]=&datetonum($temp[0]);
  1073.         $temp[1]=&datetonum($temp[1]);
  1074.         if (/^([><=]+)/) {$temp3=$1};
  1075.         $criteria=$temp3.$temp[0];
  1076.         if (/^between/i) {$criteria="between $temp[0] and $temp[1]"};
  1077.         if ($fields[$i]=~/[0-9][0-9]?\/[0-9][0-9]?\/[0-9][0-9]+/) {
  1078.             $dataval=&datetonum($fields[$i]);
  1079.         } else {
  1080.             $display="false";
  1081.         };
  1082.     } else {
  1083.         $dataval=$fields[$i];
  1084.         $criteria=$value[$i];
  1085.     };
  1086.     $_=$dataval;
  1087.     $criteria=~s/ or /\|/gi;
  1088.     $firstchar=substr($criteria,0,1);
  1089.     $combo="false";
  1090.     if (!((/$criteria/i)||($criteria eq "")||
  1091.        ($firstchar eq '<')||($firstchar eq '>')||
  1092.         ($criteria=~/ and /i))) {
  1093.         $display="false";
  1094.     };
  1095.  
  1096.     if ((substr($criteria,0,2) eq '<=')&&($_ > 
  1097. substr($criteria,2,99))) {
  1098.         $combo="true";
  1099.         $display="false";
  1100.     };
  1101.     if ((substr($criteria,0,2) eq '>=')&&($_ < 
  1102. substr($criteria,2,99))) {
  1103.         $combo="true";
  1104.         $display="false";
  1105.     };
  1106.  
  1107.     if (($combo ne "true")&&(substr($criteria,1,1) ne '=')) {
  1108.     if ((substr($criteria,0,1) eq '<')&&($_ >=
  1109. substr($criteria,1,99))) {
  1110.         $display="false";
  1111.     };
  1112.     if ((substr($criteria,0,1) eq '>')&&($_ <=
  1113. substr($criteria,1,99))) {
  1114.         $display="false";
  1115.     };
  1116.  
  1117.     if ($criteria=~/^between.* and /i) {
  1118.         $andpos = index($criteria,'and');
  1119.         if ($andpos<8) {$display="false";};
  1120.         $val1 = substr($criteria,7,$andpos);
  1121.         $val2 = substr($criteria,$andpos+4,99);
  1122.         if (($_<$val1)||($_>$val2)) {
  1123.             $display="false";
  1124.         };
  1125.     };
  1126.     if (($criteria=~/ and /i)&&(!($criteria=~/^between/i))) {
  1127.         @cdata=split(/ and /i,$criteria);
  1128.         foreach $citem (@cdata) {
  1129.             if(!(/$citem/i)) {$display="false";};
  1130.         };
  1131.     };    
  1132.     };
  1133.     };
  1134. #***** DISPLAY THE LINE ****************
  1135.     if (!$user_data{pagenum}) {
  1136.         $user_data{pagenum}=1;
  1137.         $querystring=~s/cgifunction/pagenum=1\&cgifunction/;
  1138.     };
  1139.     $pagenum=$user_data{pagenum};
  1140.     $min=($pagenum-1)*20;
  1141.     $max=$pagenum*20;
  1142.     if ($display eq "true") {
  1143.         $count++;
  1144.         if (($count>$min)&&($count<=$max)) {
  1145.             print "\n<TR>";
  1146.             foreach $n (@fields) {
  1147.               print "<TD><A HREF=\"javascript:modify(\'$ID\')\">";
  1148.               if ($n eq "") {$n = ' </A>';};
  1149.               $n=~s/[\r\n]/<BR>/g;
  1150.               print "$n</A>";
  1151.             };
  1152.         };
  1153.         push(@foundset,$ID);
  1154.     };
  1155. };
  1156.  
  1157. print "\n</table>\n";
  1158.  
  1159. $foundsetstring=join(':',@foundset);
  1160. print "<form name=\"form1\" action=\"$cgilocation\" method=post>\n";
  1161. print "<input name=\"part\" type=hidden>\n";
  1162. print "<input name=\"password\" type=hidden>\n";
  1163. print "<input name=\"cgifunction\" type=hidden value=\"maintenance\">\n";
  1164. print "<input name=\"foundset\" type=hidden value=\"$foundsetstring\">\n";
  1165. print "</form>\n";
  1166. if ($count>0) {
  1167. print "<h2>Click on an entry to modify or delete it. </h2>
  1168. <form><input type=button value=\"Delete All $count Found Records\"
  1169. onClick=\"deleteset()\"></form><BR>";
  1170.  
  1171. #BEGIN NEXT/PREV BUTTONS
  1172. $min++;
  1173.  
  1174. if ($max>$count) {$max=$count};
  1175. print "
  1176. <B>Results $min - $max of $count</B> 
  1177. <table border=0 cellspacing=10 cellpadding=0><TR><TD>
  1178. ";
  1179. if ($min>1) {print "
  1180.  
  1181. <FORM ACTION=\"$cgilocation\" METHOD=POST>
  1182. <INPUT TYPE=HIDDEN NAME=\"query\" VALUE=\"$querystring\">
  1183. <INPUT TYPE=HIDDEN NAME=\"pagenum\" VALUE=\"$pagenum\">
  1184. <INPUT TYPE=SUBMIT NAME=\"cgifunction\" value=\"Previous Page\">
  1185. </FORM>
  1186. "};
  1187. if ($max<$count) {print "
  1188. <TD>
  1189. <FORM ACTION=\"$cgilocation\" METHOD=POST>
  1190. <INPUT TYPE=HIDDEN NAME=\"query\" VALUE=\"$querystring\">
  1191. <INPUT TYPE=HIDDEN NAME=\"pagenum\" VALUE=\"$pagenum\">
  1192. <INPUT TYPE=SUBMIT NAME=\"cgifunction\" value=\"Next Page\">
  1193. </FORM>
  1194. "};
  1195. print "</table>";
  1196. #END NEXT/PREV BUTTONS
  1197. } else {
  1198.   print "<B>No records were found</B><P>";
  1199. };
  1200. #CREATE LINKS TO ANY PAGENUMBER
  1201. print "<BR>Go to page\:";  
  1202. $numpages=int($count/20);
  1203. $myquery=$querystring;
  1204. if ($count/20>$numpages) {$numpages++;};
  1205. for ($i=1;$i<=$numpages;$i++) {
  1206.     $myquery=~s/pagenum=[0-9]*/pagenum=$i/;
  1207.     print "<A HREF=\"$cgilocation\?$myquery\">$i</A> ";
  1208. };
  1209.  
  1210. print "<BR><A HREF=\"javascript:goadmin()\">Return to Administration Page</A>\n";
  1211.  
  1212. print "<P><A HREF=\"$homepage\">
  1213. Return to home page</A>\n";
  1214. };
  1215.  
  1216. #*********END OF SEARCH SUBROUTINE************
  1217.  
  1218. #**********BEGIN USERSEARCH SUBROUTINE******************
  1219. #*****Same as Search except the results****************
  1220. #*****Do not link to maintenance       ***************
  1221. #
  1222. sub usersearch {
  1223. &checkpass; #<!--FLAG4-->
  1224. pop(@value);   #** Remove cgifunction from @value array **
  1225. pop(@value);   #** Remove pagnum from @value array **
  1226. shift(@value);  #remove ID from @value array **
  1227. open(LOGFILE,"<$logfile");
  1228. @entries = <LOGFILE>;
  1229. close (LOGFILE);
  1230.  
  1231. open(REPORT, "<$reportdata"); 
  1232. @reportData=<REPORT>;
  1233. close REPORT;
  1234. $reportColor=$reportData[0];
  1235. chop($reportColor);
  1236. $reportHeader=$reportData[1];
  1237. chop($reportHeader);
  1238. $reportHeader=~s/\<\;/</g;
  1239. $reportHeader=~s/::/\n/g;
  1240. $reportSequence=$reportData[2];
  1241. chop($reportSequence);
  1242. @sequence=split(/:/,$reportSequence);
  1243. $reportSort=$reportData[3];
  1244. chop($reportSort);
  1245. $reportOrder=$reportData[4];
  1246. chop($reportOrder);
  1247. $reportLines=$reportData[5];
  1248. chop($reportLines);
  1249. $reportForm=$reportData[6];
  1250. chop($reportForm);
  1251.  
  1252.  
  1253. #PARSE/SORT ROUTINE
  1254. if ($reportSort>0) {
  1255. #...populate sorting array
  1256. $sortcount=0;
  1257. $textsort="false";
  1258. foreach (@entries) {
  1259.     @data=split(/::/);
  1260.     $val=$data[$reportSort];
  1261.     if ($val=~/^[0-9][0-9]?\/[0-9][0-9]?\/[0-9][0-9]*$/) {$val=&datetonum($val)};
  1262.     if ($val=~/[a-zA-Z]/) {$textsort="true"};
  1263.     $sortarray{$sortcount}=$val;
  1264.     $sortcount++;
  1265. };
  1266.  
  1267. if ($reportOrder==1) {$bottom="\$a";$top="\$b"} else {$top="\$a";$bottom="\$b"};
  1268. if ($textsort eq "true") {$oper="cmp"} else {$oper="<=>"};
  1269. eval('@sortarray=sort {$sortarray{'.$top.'} '.$oper.' $sortarray{'.$bottom.'}} keys %sortarray;');
  1270.  
  1271. foreach (@sortarray) {push(@temp,$entries[$_])};
  1272. @entries=@temp;    
  1273. };
  1274.  
  1275. print "<HEAD><TITLE>Search Results page $user_data{pagenum}</TITLE></HEAD>";
  1276. print "<BODY BGCOLOR=\"$reportColor\">\n";
  1277. print "$reportHeader\n";
  1278. if (!$user_data{pagenum}) {
  1279.     $user_data{pagenum}=1;
  1280.     $querystring=~s/cgifunction/pagenum=1\&cgifunction/;
  1281. };
  1282. $pagenum=$user_data{pagenum};
  1283. print "<FORM><TABLE BORDER=1 bgcolor=\"white\">\n";
  1284.  
  1285. open(FIELDS,"<$fieldnames")||die "Could not open $fieldnames";
  1286. @fieldsData=<FIELDS>;
  1287. close FIELDS;
  1288. foreach (@fieldsData) {
  1289.     ($field,$type)=split(/::/);
  1290.     push(@fields,"$field\n");
  1291.     push(@types,"$type");
  1292. };
  1293. shift(@fields);
  1294. #POPULATE @VALUE INDEPENDENT OF SEQUENCE
  1295. $fcount=0;
  1296. foreach (@fields) {
  1297.     chop($_);
  1298.     $value[$fcount]=$user_data{$_};
  1299.     $fcount++;
  1300. };
  1301.  
  1302.  
  1303. $header= "<TR>";
  1304. if ($reportForm==1) {$header.="<TH>";};
  1305. foreach (@sequence) {
  1306.     $header .= "<TH>$fields[$_]";
  1307. };
  1308. print  "$header\n";
  1309. #***** BEGIN STEPPING THROUGH ALL THE DATA LINES*****
  1310. #***** PARSE THE DATA *****************
  1311. $date=0;
  1312. foreach $line (@entries) {
  1313.     @fields = split(/::/,$line);
  1314.     $id=$fields[0];
  1315.     shift(@fields); #**Remove hidden key from view**
  1316.     pop(@fields); #**Remove membername from view**
  1317.  
  1318. # *** IF LINE MATCHES PATTERN ***********
  1319.     $display="true";
  1320.     $numPairs=@value;
  1321.     for ($i=0;$i<$numPairs;$i++) {
  1322.     if ($value[$i]=~/[0-9][0-9]?\/[0-9][0-9]?\/[0-9][0-9]+/) {
  1323.         $_=$value[$i];
  1324.         @temp=m/([0-9][0-9]?\/[0-9][0-9]?\/[0-9][0-9]+)/g;
  1325.         $temp[0]=&datetonum($temp[0]);
  1326.         $temp[1]=&datetonum($temp[1]);
  1327.         if (/^([><=]+)/) {$temp3=$1};
  1328.         $criteria=$temp3.$temp[0];
  1329.         if (/^between/i) {$criteria="between $temp[0] and $temp[1]"};
  1330.         if ($fields[$i]=~/[0-9][0-9]?\/[0-9][0-9]?\/[0-9][0-9]+/) {
  1331.             $dataval=&datetonum($fields[$i]);
  1332.         } else {
  1333.             $display="false";
  1334.         };
  1335.     } else {
  1336.         $dataval=$fields[$i];
  1337.         $criteria=$value[$i];
  1338.     };
  1339.     $_=$dataval;
  1340.     $criteria=~s/ or /\|/gi;
  1341.     $firstchar=substr($criteria,0,1);
  1342.     $combo="false";
  1343.     if (!((/$criteria/i)||($criteria eq "")||
  1344.        ($firstchar eq '<')||($firstchar eq '>')||
  1345.         ($criteria=~/ and /i))) {
  1346.         $display="false";
  1347.     };
  1348.  
  1349.     if ((substr($criteria,0,2) eq '<=')&&($_ > 
  1350. substr($criteria,2,99))) {
  1351.         $combo="true";
  1352.         $display="false";
  1353.     };
  1354.     if ((substr($criteria,0,2) eq '>=')&&($_ < 
  1355. substr($criteria,2,99))) {
  1356.         $combo="true";
  1357.         $display="false";
  1358.     };
  1359.  
  1360.     if (($combo ne "true")&&(substr($criteria,1,1) ne '=')) {
  1361.     if ((substr($criteria,0,1) eq '<')&&($_ >=
  1362. substr($criteria,1,99))) {
  1363.         $display="false";
  1364.     };
  1365.     if ((substr($criteria,0,1) eq '>')&&($_ <=
  1366. substr($criteria,1,99))) {
  1367.         $display="false";
  1368.     };
  1369.  
  1370.     if ($criteria=~/^between.* and /i) {
  1371.         $andpos = index($criteria,'and');
  1372.         if ($andpos<8) {$display="false";};
  1373.         $val1 = substr($criteria,7,$andpos);
  1374.         $val2 = substr($criteria,$andpos+4,99);
  1375.         if (($_<$val1)||($_>$val2)) {
  1376.             $display="false";
  1377.         };
  1378.     };
  1379.     if (($criteria=~/ and /i)&&(!($criteria=~/^between/i))) {
  1380.         @cdata=split(/ and /i,$criteria);
  1381.         foreach $citem (@cdata) {
  1382.             if(!(/$citem/i)) {$display="false";};
  1383.         };
  1384.     };    
  1385.     };
  1386.     };    
  1387. #***** DISPLAY THE LINE ****************
  1388.     $min=($pagenum-1)*$reportLines;
  1389.     $max=$pagenum*$reportLines;
  1390.     if ($display eq "true") {
  1391.         $count++;
  1392.         if (($count>$min)&&($count<=$max)) {
  1393.             print "\n<TR>";
  1394.             if ($reportForm==1) {
  1395.                 print "<TD><input type=button value=\"view\"";
  1396.                 print " onClick=\"viewform($id,\'$querystring\')\">"; 
  1397.             };
  1398.  
  1399.  
  1400. #***** BEGIN DISPLAY DATA LOOP *******
  1401.             foreach (@sequence) {
  1402.                 $n=$fields[$_];
  1403.                 $n=~s/\r/<BR>/g;
  1404.                 if ($n eq "") {$n=' ';};
  1405.     $n=~s/^([0-9a-zA-Z_\-\.\~]+\@[0-9a-zA-Z_\-\.\~]+\.[0-9a-zA-Z_\-\.\~]+)/<A HREF=mailto:$1>$1<\/A>/;
  1406.     if ($n=~/^([^ ]+\.(gif|jpg))$/) {$n="<IMG SRC=$1>"} else {$n=~s/^(http[^ ]+)/<A HREF=$1>$1<\/A>/;};
  1407.                   print "<TD>$n";
  1408.             };
  1409. #***** END DISPLAY DATA LOOP *********
  1410.         };
  1411.     };
  1412.  
  1413. };
  1414. print "\n</table></form>\n";
  1415. if ($count>0) {
  1416. print " 
  1417. <SCRIPT LANGUAGE=JavaScript> 
  1418. function viewform(id,q) { 
  1419. document.vf.id.value=id\; 
  1420. document.vf.query.value=q\; 
  1421. document.vf.submit()\; 
  1422. </SCRIPT> 
  1423. <FORM NAME=\"vf\" ACTION=\"$cgilocation\" METHOD=POST> 
  1424. <INPUT TYPE=HIDDEN NAME=\"id\"> 
  1425. <INPUT TYPE=HIDDEN NAME=\"query\"> 
  1426. <INPUT TYPE=HIDDEN NAME=\"cgifunction\" VALUE=\"form\"> 
  1427. </FORM>\n"; 
  1428. $min++;
  1429. if ($max>$count) {$max=$count};
  1430.  
  1431.     print "
  1432. <B>Results $min - $max of $count</B> 
  1433. <table border=0 cellspacing=10 cellpadding=0><TR><TD>
  1434. ";
  1435. if ($min>1) {print "
  1436.  
  1437. <FORM ACTION=\"$cgilocation\" METHOD=POST>
  1438. <INPUT TYPE=HIDDEN NAME=\"query\" VALUE=\"$querystring\">
  1439. <INPUT TYPE=HIDDEN NAME=\"pagenum\" VALUE=\"$pagenum\">
  1440. <INPUT TYPE=SUBMIT NAME=\"cgifunction\" value=\"Previous Page\">
  1441. </FORM>
  1442. "};
  1443. if ($max<$count) {print "
  1444. <TD>
  1445. <FORM ACTION=\"$cgilocation\" METHOD=POST>
  1446. <INPUT TYPE=HIDDEN NAME=\"query\" VALUE=\"$querystring\">
  1447. <INPUT TYPE=HIDDEN NAME=\"pagenum\" VALUE=\"$pagenum\">
  1448. <INPUT TYPE=SUBMIT NAME=\"cgifunction\" value=\"Next Page\">
  1449. </FORM>
  1450.      "};
  1451. #CREATE LINKS TO ANY PAGENUMBER
  1452. print "<TR><TD>Go to page\:";  
  1453. $numpages=int($count/$reportLines);
  1454. $myquery=$querystring;
  1455. if ($count/$reportLines>$numpages) {$numpages++;};
  1456. for ($i=1;$i<=$numpages;$i++) {
  1457.     $myquery=~s/pagenum=[0-9]*/pagenum=$i/;
  1458.     print "<A HREF=\"$cgilocation\?$myquery\">$i</A> ";
  1459. };
  1460.  
  1461.  
  1462. } else {
  1463.      print "<B>No results were found.</B><P>"
  1464. };
  1465. print "<TD><A HREF=\"$searchpage\"><B>Search Again</B></A>\n";
  1466. print "<TD><A HREF=\"$homepage\">
  1467. <B>Return to home page</B></A>\n</TABLE>";
  1468. };
  1469. #*********END OF USERSEARCH SUBROUTINE************
  1470.  
  1471. #*********BEGIN MAINTENANCE SUBROUTINE********
  1472. sub maintenance {
  1473. &memberpass;
  1474. pop(@value);
  1475.  
  1476. open(READLOG,"<$logfile");
  1477. @entries = <READLOG>;
  1478. close READLOG;
  1479. foreach $line (@entries) {
  1480.     @fields = split(/::/,$line);
  1481.     if ($fields[0] eq $value[0]) {
  1482.         print "
  1483.  
  1484. <SCRIPT>
  1485. function del() {
  1486. if (confirm(\"Are you sure you want to delete this entry?\")) {
  1487. document.form1.cgifunction.value=\"delete\"\;
  1488. document.form1.submit()\;
  1489. }}
  1490.  
  1491. function modify() {
  1492. document.form1.cgifunction.value=\"modify\"\;
  1493. document.form1.submit()\;
  1494. }
  1495.  
  1496. function datecheck(cell) {
  1497.   text=cell.value\;
  1498.   slash=text.lastIndexOf(\"/\")\;
  1499.   year=parseInt(text.substring(slash+1,99))\;
  1500.   if (year<=50) {year=year+2000}\;
  1501.   if ((year>50)&&(year<=99)) {year=year+1900}\;
  1502.   result = text.substring(0,slash+1)+year\;
  1503.   cell.value=result\;
  1504. }
  1505.  
  1506. function goadmin() {
  1507. document.form1.cgifunction.value=\"admin\";
  1508. document.form1.submit()\;
  1509. }
  1510. </SCRIPT>
  1511.  
  1512.  
  1513. <HEAD><TITLE>Modify or delete record</TITLE></HEAD>
  1514. <BODY BGCOLOR=\"beige\">
  1515. <H1 align=center> Maintenance Page </H1>
  1516. <form name=\"form1\" action=\"$cgilocation\" method=post>
  1517. <TABLE BORDER=0>
  1518. ";
  1519. @fields=();
  1520. open(FIELDS,"<$fieldnames")||die "Could not open $fieldnames";
  1521. @fieldsData=<FIELDS>;
  1522. close FIELDS;
  1523. foreach (@fieldsData) {
  1524.     ($field,$type)=split(/::/);
  1525.     push(@fields,"$field\n");
  1526.     push(@types,"$type");
  1527. };
  1528.  
  1529. shift(@fields);
  1530. shift(@types);
  1531. open(READLOG,"<$logfile");
  1532. @entries = <READLOG>;
  1533. close READLOG;
  1534. foreach $entry (@entries) {
  1535.     @parsed = split(/::/,$entry);
  1536.     if ($parsed[0] eq $value[0]) {@data = @parsed};
  1537. };
  1538.  
  1539.  
  1540. $num = @fields;
  1541. print "<TR><TD><B>ID<TD><input type=hidden name=\"ID\" value=\"$data[0]\"><B>$data[0]\n";
  1542. shift(@data);
  1543. $ftcount=0;
  1544. foreach $field (@fields) {
  1545.       $data[$ftcount]=~s/\"/\"\;/g;
  1546.       &gettype($types[$ftcount]);
  1547.       chop($field);
  1548.       if ($type eq "text") {
  1549.             print "<TR><TD><B>$field<TD><input type=$type name=\"$field\" size=$typesize
  1550.             value=\"$data[$ftcount]\">\n";
  1551.       };
  1552.  
  1553.       if ($type eq "checkbox") {
  1554.             print "<TR><TD><B>$field<TD><input type=$type name=\"$field\" value=\"yes\"";
  1555.           if ($data[$ftcount] eq "yes") {print " CHECKED"};
  1556.           print ">";
  1557.       };
  1558.       if ($type eq "list") {
  1559.             print "<TR><TD><B>$field<TD><SELECT NAME=\"$field\" SIZE=1>\n";
  1560.           print "<OPTION VALUE=\"\">\n";
  1561.           foreach (@typelistvals) {
  1562.             print "<OPTION";
  1563.             if ($_ eq $data[$ftcount]) {print " SELECTED"};
  1564.             print ">$_\n";
  1565.           };
  1566.           print "</SELECT>\n";
  1567.       };
  1568.       if ($type eq "comment") {
  1569.           $data[$ftcount]=~s/<BR>/\n/g;
  1570.           print "<TR><TD><B>$field<TD><TEXTAREA NAME=\"$field\" COLS=60 ROWS=$typerows>$data[$ftcount]</TEXTAREA>\n";
  1571.       };
  1572.       $ftcount++;
  1573. };
  1574. print "
  1575. <TR><TD colspan=4><input type=button value=\"modify\" onClick=\"modify()\">
  1576. <input type=button value=\"Delete\" onClick=\"del()\">
  1577.  
  1578.  
  1579. <input type=hidden name=\"cgifunction\">
  1580. </TABLE></FORM>
  1581.  
  1582. <h2>Modify will save the record with the new values.<BR>Delete will remove the record from the table</h2>
  1583.  
  1584. <A HREF=\"javascript:goadmin()\">Return to Administration Page</A>
  1585. <P>
  1586.  
  1587. <A HREF=\"$homepage\">
  1588. Return to home page</A>
  1589. ";
  1590. };
  1591. };
  1592.  
  1593.  
  1594.  
  1595. };
  1596. #*********END MAINTENANCE SUBROUTINE*******
  1597.  
  1598.  
  1599.  
  1600. #**** BEGIN MODIFY SUBROUTINE *****
  1601. sub modify {
  1602. &memberpass;
  1603. pop(@value);
  1604. open(READLOG,"<$logfile");
  1605. @entries = <READLOG>;
  1606. close READLOG;
  1607. foreach $item (@value) {
  1608.     $item=~s/^( *)//ge;   # remove leading spaces from entries
  1609.     $item=~s/::/'::'/ge;  # replace delimiting character from entries
  1610.     $item=~s/\r/\n/g;
  1611.     $item=~s/\n\n/\n/g;
  1612.     $item=~s/\n/<BR>/g;
  1613. };
  1614. @fields=();
  1615. @types=();
  1616. open(FIELDS,"<$fieldnames")||die "Could not open $fieldnames";
  1617. @fieldsData=<FIELDS>;
  1618. close FIELDS;
  1619. foreach (@fieldsData) {
  1620.     ($field,$type)=split(/::/);
  1621.     push(@fields,"$field\n");
  1622.     push(@types,"$type");
  1623. };
  1624. shift(@fields);
  1625. shift(@types);
  1626. foreach $line (@entries) {
  1627.         @data=split(/::/,$line);
  1628.       $len=@data;
  1629.       $owner=$data[$len-1];
  1630.       chop($owner);
  1631.         if ($data[0] eq $value[0]) {
  1632.         if (($owner eq $userid)||($userid eq "admin")) {
  1633.         @value=($data[0]);
  1634.         $fcount=1;
  1635.         foreach (@fields) {
  1636.             chop($_) if (/\n$/);
  1637.             $value[$fcount]=$user_data{$_};
  1638.             $fcount++;
  1639.         };
  1640.         foreach $item (@value) {
  1641.             $item=~s/^( *)//ge;   # remove leading spaces from entries
  1642.             $item=~s/::/'::'/ge;  # replace delimiting character from entries
  1643.             $item=~s/\r/\n/g;
  1644.             $item=~s/\n\n/\n/g;
  1645.             $item=~s/\n/<BR>/g;
  1646.         };
  1647.             push(@value,$owner);
  1648.                 $line=join("::",@value)."\n";
  1649.           };
  1650.         };
  1651. };
  1652. open(PUTLOG,">$logfile");
  1653. print PUTLOG (@entries);
  1654. close PUTLOG;
  1655.  
  1656. @value=();
  1657. if ($userid eq "admin") {&admin} else {&memberpage};
  1658. };
  1659. #***** END MODIFY SUBROUTINE*******
  1660.  
  1661.  
  1662. #******* BEGIN DELETE SUBROUTINE ******
  1663. sub delete {
  1664. &memberpass;
  1665. pop(@value);
  1666. open(READLOG,"<$logfile");
  1667. @entries = <READLOG>;
  1668. close READLOG;
  1669.  
  1670. foreach $line (@entries) {
  1671.         @fields=split(/::/,$line);
  1672.       $len=@fields;
  1673.       $owner=$fields[$len-1];
  1674.       chop($owner);
  1675.         if (($fields[0] ne $value[0])||(($userid ne "admin")&&($userid ne $owner))) {
  1676.                 push(@result,$line);
  1677.         };
  1678. };
  1679.  
  1680. open(PUTLOG, ">$logfile") || die "Content-type: text/html\n\n
  1681. <BODY BGCOLOR=WHITE><CENTER><H2>Could not open the file $logfile<P>
  1682. If you have moved the file, you can correct this by changing lines 10 and 11
  1683. of the webdata_[database name].cgi script to show the absolute path to the file.<P><P><P></h2>
  1684. This cgi error was ";
  1685. print PUTLOG (@result);
  1686. close PUTLOG;
  1687.  
  1688. @value=();
  1689. if ($userid eq "admin") {&admin} else {&memberpage};
  1690. };
  1691. #****** END DELETE SUBROUTINE *******
  1692.  
  1693. #****** BEGIN CACHE********
  1694. sub cache {
  1695. open(FIELDS,"<$fieldnames")||die "Could not open $fieldnames";
  1696. @fields=<FIELDS>;
  1697. close FIELDS;
  1698. if (&fieldnames($value[0]) eq "true") {
  1699. $fields[0] = "$value[0]\n";
  1700. open(FIELDS,">$fieldnames");
  1701. print FIELDS (@fields);
  1702. close FIELDS;
  1703. @value=();
  1704. &admin;
  1705. } else {
  1706. print "incorrect registration";
  1707. };
  1708. };
  1709.  
  1710. #****** END CACHE ********
  1711.  
  1712. #****** BEGIN ADMIN SUBROUTINE ******
  1713. sub admin {
  1714. pop(@value);
  1715. &checkpass;
  1716.  
  1717. open(FIELDS,"<$fieldnames") || die "Content-type: text/html\n\n
  1718. <BODY BGCOLOR=WHITE> <h2>Could not open <font color=blue>$fieldnames</font>  <P>
  1719. Make sure the path is correct.  If you have moved the data files, you can
  1720. correct this by changing lines 10 and 11 in the cgi script.<P><BR></P>
  1721. <P><BR></P><P><BR></P><P><BR></P></h2><font size=3>This cgi error was ";
  1722. @cache = <FIELDS>;
  1723. close FIELDS;
  1724. chop($cache[0]);
  1725. $cacheval = substr(@cache[0],0,7);
  1726. if (&fieldnames($cache[0]) ne 'true') {
  1727.   if ($cacheval eq "webdata") {
  1728.       $num=substr(@cache[0],7,99);
  1729.       $num = int(30-((time()-$b)/86400));
  1730.     @parse=(82,101,103,105,115,116,114,97,116,105,111,110,32,21,101,120,112,105,114,101,100);
  1731.       if($num<0) {foreach (@parse) {print (chr($_))};exit;}
  1732.  
  1733.       print "
  1734.  
  1735. <font size=4 color=green><B>";
  1736. for ($m=0;$m<67;$m++) {print chr(hex($import[$m]))};
  1737. print "$num";
  1738. for ($m=66;$m<101;$m++) {print chr(hex($import[$m]))};
  1739. print "<BR><B>ID Code=$code</B>
  1740. <A HREF=\"http://www.webteacher.com/webdata/register.htm\">
  1741. Click here to Register</A>
  1742. </B></font>
  1743. <BR>
  1744. <form name=\"form3\" action=\"$cgilocation\" method=post>
  1745. Enter your code:<input name=\"box1\" type=text size=15>
  1746. <input name=\"cgifunction\" type=hidden value=\"cache\">
  1747. <input type=submit value=\"submit registration\">
  1748. </form>
  1749. ";
  1750.  
  1751. } else {
  1752.     print "There is a problem with the registration code or date log.";
  1753.     exit
  1754. };
  1755. };
  1756.  
  1757.     print "<script>document.cookie=\"admin=$password\"</script>\n";
  1758.     print "
  1759. <HEAD><TITLE>Webdata Admin Page</TITLE></HEAD>
  1760. <BODY BGCOLOR=\"beige\">
  1761. <H1 align=center> Administration Page </H1>
  1762. <form name=\"form1\" action=\"$cgilocation\" method=post>
  1763. <TABLE BORDER=0>
  1764. ";
  1765. @fields=();
  1766. @types=();
  1767. open(FIELDS,"<$fieldnames")||die "Could not open $fieldnames";
  1768. @fieldsData=<FIELDS>;
  1769. close FIELDS;
  1770. foreach (@fieldsData) {
  1771.     ($field,$type)=split(/::/);
  1772.     push(@fields,"$field\n");
  1773.     push(@types,"$type");
  1774. };
  1775. shift(@fields);
  1776. shift(@types);
  1777.  
  1778. foreach $field (@fields) {
  1779.       &gettype($types[$ftcount]);
  1780.       chop($field);
  1781.       if ($type eq "text") {
  1782.             print "<TR><TD><B>$field<TD><input type=$type name=\"$field\" size=$typesize>\n";
  1783.       };
  1784.       if ($type eq "checkbox") {
  1785.           print "<TR><TD><B>$field<TD><input type=checkbox name=\"$field\" value=\"yes\">\n";
  1786.       };
  1787.       if ($type eq "list") {
  1788.             print "<TR><TD><B>$field<TD><SELECT NAME=\"$field\" SIZE=1>\n";
  1789.           print "<OPTION VALUE=\"\">\n";
  1790.           foreach (@typelistvals) {
  1791.             print "<OPTION>$_\n";
  1792.           };
  1793.           print "</SELECT>\n";
  1794.       };
  1795.       if ($type eq "comment") {
  1796.           print "<TR><TD><B>$field<TD><TEXTAREA NAME=\"$field\" COLS=60 ROWS=$typerows></TEXTAREA>\n";
  1797.       };
  1798.       $ftcount++;
  1799. };
  1800.  
  1801. print "
  1802.  
  1803.  
  1804. </TABLE>
  1805. <INPUT TYPE=SUBMIT NAME=\"cgifunction\" VALUE=\"Add\">
  1806. <INPUT TYPE=SUBMIT NAME=\"cgifunction\" VALUE=\"Search/modify\">
  1807. <INPUT TYPE=RESET VALUE=\"Clear Form\"><P><HR>
  1808. <INPUT TYPE=SUBMIT NAME=\"cgifunction\" VALUE=\"Import data\">
  1809. <INPUT TYPE=SUBMIT NAME=\"cgifunction\" VALUE=\"Export data\">
  1810. <INPUT TYPE=SUBMIT NAME=\"cgifunction\" VALUE=\"Modify fields\"><P>
  1811. <INPUT TYPE=SUBMIT NAME=\"cgifunction\" VALUE=\"Members\">
  1812. <INPUT TYPE=SUBMIT NAME=\"cgifunction\" VALUE=\"Customize Pages\">
  1813. </FORM> 
  1814.  
  1815.  
  1816. <h2>
  1817. Click \'Add\' to add a record to the database.
  1818.  
  1819. <P>To modify or delete a record: Search for the record, then click on the record in the search results window.</h2>
  1820.  
  1821. <A HREF=\"$homepage\">
  1822. Return to home page</A>
  1823.  
  1824. ";
  1825.  
  1826. };
  1827.  
  1828.  
  1829. #********END ADMIN SUBROUTINE***************
  1830.  
  1831. #********BEGIN IMPORT USER PAGE**************
  1832. sub import {
  1833. &checkpass;
  1834. print "
  1835. <HEAD><TITLE>Webdata Import Data</TITLE></HEAD>
  1836. <BODY BGCOLOR=\"BEIGE\">
  1837. <h1 align=\"center\">Import a delimeted text file</h1>
  1838. <h4>A delimeter is a character which is used to tell the database
  1839. where one field stops, and the next one begins.  Most spreadsheet
  1840. and database programs can save as either comma delimeted or tab 
  1841. delimeted.  <P>
  1842.  
  1843. This program will convert comma or tab delimeted text files to 
  1844. Webdata\'s format, and append the file to your existing database.
  1845.   The imported data file should be in the same sequence as your
  1846. existing data.  Microsoft Excel is a good tool for resequencing
  1847. data before saving to a delimeted text file.  <P></h4>
  1848.  
  1849. <B>Save the data in your other database program as
  1850. comma or tab delimeted, then use your FTP program to upload it to your server.  
  1851. You will need the full path name for the file, for example</B><BR>
  1852.    <TT>/user/local/robyoung/webdata/mydata.txt</TT><BR>
  1853. <P><B><font size=3>
  1854. What is the full path name of the data file?<BR></font>
  1855. <form action=\"$cgilocation\" method=\"post\">
  1856. <input type=text name=\"filename\" size=60><BR>
  1857. <font size=3>
  1858. Is the file comma or tab delimeted?</font>
  1859. <select name=\"delimeter\" size=1>
  1860. <option value=\"comma\">comma
  1861. <option value=\"tab\">tab
  1862. </select>
  1863. <input type=hidden name=\"cgifunction\" value=\"import2\">
  1864. <INPUT TYPE=SUBMIT VALUE=\"Import\">
  1865. </form>";
  1866. };
  1867. sub fieldnames {
  1868. if ($_[0] eq crypt($a,$code)) {return 'true'} else {return 0};
  1869. };
  1870.  
  1871. #********BEGIN IMPORT DATA CONVERSION****************
  1872. sub import2 {
  1873. &checkpass;
  1874. $file = $user_data{filename};
  1875. $dlmtr = $user_data{delimeter};
  1876.  
  1877. open(FILE,"<$file") || die print "Could not open file $file";
  1878. @file = <FILE>;
  1879. close FILE;
  1880. $count=time();
  1881. $count=$count-90000000;
  1882. if ($dlmtr eq 'comma') {$dlmtr=','} else {$dlmtr="\t"};
  1883. foreach $line (@file) {
  1884. $line =~ s/$dlmtr/'::'/ge;
  1885. chop($line);
  1886. $line = $count."::$line"."::admin\n";
  1887. $count++;
  1888. };
  1889. open(DATA,">>$logfile");
  1890. print DATA (@file);
  1891. close DATA;
  1892.  
  1893. print "<h1>Data Import complete</h1>";
  1894. &admin;
  1895. };
  1896. sub fieldnames {
  1897. if ($_[0] eq crypt($a,$code)) {return 'true'} else {return 0};
  1898. };
  1899.  
  1900. #********END IMPORT DATA CONVERSIONS*******************
  1901. #********BEGIN EXPORT USER PAGE**********************
  1902. sub export {
  1903. print "
  1904. <BODY BGCOLOR=\"BEIGE\">
  1905. <H1 ALIGN=\"CENTER\">Export the database to a delimeted text file</H1>
  1906. <FORM ACTION=\"$cgilocation\" method=POST><B>Please type a full pathname on the server you would
  1907. like to name the exported file.  For example <TT>/user/home/export.txt</TT> <BR>You will then use your FTP program to download the exported data.<P></B>
  1908.  
  1909. If you have difficulty, check the permissions of that folder.
  1910.  
  1911. <P>
  1912.  
  1913. <INPUT TYPE=text NAME=\"path\"><BR>
  1914.  Would you like the file comma or tab delimeted?</font>
  1915. <select name=\"delimeter\" size=1>
  1916. <option value=\"comma\">comma
  1917. <option value=\"tab\">tab
  1918. </select>
  1919. <BR>
  1920. Include field names in first row?
  1921. <input name=\"fields\" type=checkbox><BR>
  1922. <input name=\"cgifunction\" type=hidden value=\"export2\">
  1923. <input type=submit value=\"Export Data\">
  1924. </FORM>
  1925. ";
  1926. };
  1927. #********END EXPORT USER PAGE**********************
  1928. #********BEGIN EXPORT DATA CONVERSIONS************
  1929. sub export2 {
  1930.     &checkpass;
  1931.     if ($value[1] eq "comma") {$dlmtr=','};
  1932.     if ($value[1] eq "tab") {$dlmtr="\t"};
  1933.     open(DATA,"<$logfile");
  1934.     @data=<DATA>;
  1935.     close DATA;
  1936.     foreach (@data) {
  1937.     @line=split(/::/);
  1938.     shift(@line);
  1939.     pop(@line);
  1940.     $_=join($dlmtr,@line);
  1941.     $_.="\n";
  1942.     };
  1943.     if ($user_data{fields} eq "on") {
  1944.     open(FIELDS,"<$fieldnames")||die "Could not open $fieldnames";
  1945.     @fieldsData=<FIELDS>;
  1946.     close FIELDS;
  1947.     foreach (@fieldsData) {
  1948.         ($field,$type)=split(/::/);
  1949.         push(@fields,"$field\n");
  1950.         push(@types,"$type");
  1951.     };
  1952.     foreach (@fields) {chop($_)};
  1953.     shift(@fields);
  1954.     $firstline=join($dlmtr,@fields);
  1955.     unshift(@data,"$firstline\n");
  1956.     };
  1957.     open(OUTFILE,">$value[0]");
  1958.     print OUTFILE (@data);
  1959.     close OUTFILE;
  1960.     open(TEST,"<$value[0]")||die "Could not save $value[0], check privilages";
  1961.     @test=<TEST>;
  1962.     $len=@test;
  1963.     close TEST;
  1964.     if ($len==0) {print "Could not save $value[0], check privilages"} else {&admin};
  1965. };
  1966.  
  1967. #******** END BODY************************
  1968. #
  1969. # EACH VALUE IN THE HTML FORM WILL BE CONTAINED IN
  1970. # THE THE @VALUE ARRAY.
  1971. sub readparse {
  1972. if (length($_[0])>0) {
  1973.     $user_string=$_[0]
  1974. } else {
  1975.     read(STDIN,$user_string,$ENV{'CONTENT_LENGTH'});
  1976. };
  1977. if (length($ENV{'QUERY_STRING'})>0) {$user_string=$ENV{'QUERY_STRING'};};
  1978. if (length($_[0])>0) {$user_string=$_[0]};
  1979. $querystring=$user_string;
  1980. $user_string =~ s/\+/ /g;
  1981. @name_value_pairs = split(/&/,$user_string);
  1982. foreach $name_value_pair (@name_value_pairs) {
  1983.         ($keyword,$value) = split(/=/,$name_value_pair);
  1984.         $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/ge;
  1985.         $keyword =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/ge;
  1986.       if ($value =~ /\#exec/i) {
  1987.          print "Content-type: text/html\n\n No SSI commands permitted."; 
  1988.          exit;
  1989.       };
  1990.         push(@value, "$value");
  1991.                                 if (length($user_data{$keyword})>0) { 
  1992.                                                 $user_data{$keyword}.=" or $value"; 
  1993.                                 } else { 
  1994.                                                 $user_data{$keyword} = $value; 
  1995.                                 };
  1996.     };
  1997. @import=(54,68,69,73,20,69,73,20,61,20,74,72,69,61,'6C',20,76,65,72,73,69,'6F','6E',20);
  1998. push(@import,'6F',66,20,57,65,62,64,61,74,61,'2E',20,57,65,62,64,61,74,61,20,77,69,'6C');
  1999. $key=896189029; #<!--FLAG5-->
  2000. eval("\$"."a"."=at98ad01b01ew");
  2001. push(@import,'6C',20,73,65,'6C',66,20,64,65,73,74,72,75,63,74,20,69,'6E',20,20,64,61,79,73);
  2002. eval("\$"."b"."="."\$"."k"."ey");
  2003. push(@import,20,77,69,74,68,'6F',75,74,20,61,20,72,65,67,69,73,74,72,61,74,69,'6F','6E',20,63,'6F',64,65);
  2004. };
  2005.  
  2006. sub checkpass {
  2007.     if (!(($ENV{HTTP_COOKIE}=~/$password/)||($user_data{password} eq $password))) {   
  2008.        print "incorrect password. Be sure cookies are enabled on your browser.";
  2009.        print "<A HREF=\"javascript:history.go(-1)\"><h2>Go Back</h2></A>\n";
  2010.        exit;
  2011.     } else {
  2012.     $userid="admin";
  2013.     return;
  2014.     };
  2015. };
  2016.  
  2017. sub memberpass {
  2018.     if ((exists($user_data{username}))&&(exists($user_data{password}))) {
  2019.         $cpass=crypt($value[1],7);
  2020.         $cookie="admin=$value[0]::$cpass";
  2021.      $ENV{HTTP_COOKIE}=$cookie;
  2022.     } else {
  2023.         $cookie=$ENV{HTTP_COOKIE};
  2024.     };
  2025.     open(FILE,"<$members");
  2026.     @members=<FILE>;
  2027.     close FILE;
  2028.     $ok="false";
  2029.     foreach (@members) {
  2030.         chop($_);
  2031.         if (($cookie=~/$_/)||($_=~/$cookie/)) {
  2032.             $ok="true";
  2033.             ($user,$pass)=split(/::/);
  2034.             $userid=$user;
  2035.         };
  2036.     };
  2037.     if ($ok eq "false") {    
  2038.         &checkpass;
  2039.     };
  2040. };
  2041.  
  2042. sub datetonum {
  2043.     @parts=split(/\//,$_[0]);
  2044.     if ($parts[2]<100) {
  2045.         if ($parts[2]<20) {
  2046.             $parts[2]+=2000;
  2047.         } else {
  2048.             $parts[2]+=1900;
  2049.         };
  2050.     };
  2051.     $result=($parts[2]*1000000)+($parts[0]*1000)+$parts[1];
  2052.     #FOR EUROPEAN DATES COMMENT OUT THE LINE ABOVE AND UNCOMMENT THE LINE BELOW
  2053.     #result=($parts[2]*10000000)+($parts[1]*10000)+$parts[0];
  2054.     return($result);
  2055. };
  2056.  
  2057. sub gettype {
  2058.     @typedata=split(/:/,$_[0]);
  2059.     $type=$typedata[0];
  2060.     if ($type eq "text") {$typesize=$typedata[1];chop($typesize)};
  2061.     if ($type eq "checkbox\n") {chop($type)};
  2062.     if ($type eq "list") {
  2063.         chop($typedata[1]);
  2064.         @typelistvals=split(/,/,$typedata[1]);
  2065.     };
  2066.     if ($type eq "comment") {
  2067.         chop($typedata[1]);
  2068.         $typerows=$typedata[1];
  2069.     };
  2070. };
  2071.